<template>
  <view>
    <!-- 专辑背景开始 -->
    <view class="album_bg">
      <image :src="album.cover" mode="widthFix" />
      <view class="album_info">
        <view class="album_name" v-text="album.name"></view>
        <view class="album_btn">关注专辑</view>
      </view>
    </view>
    <!-- 专辑背景结束 -->
    <!-- 专辑作者开始 -->
    <view class="album_author">
      <view class="album_author_info">
        <image :src="album.user.avatar" mode="widthFix" />
        <view class="album_author_name" v-text="album.user.name"></view>
      </view>
      <view class="album_author_desc">
        <!-- 转义 \n -->
        <text v-text="album.desc"></text>
      </view>
    </view>
    <!-- 专辑作者结束 -->
    <!-- 列表开始 -->
    <view class="album_list">
      <view
        class="album_item"
        v-for="(item, index) in wallpaper"
        :key="item.id"
      >
        <go-detail :list="wallpaper" :index="index">
          <image
            :src="item.thumb + item.rule.replace('$<Height>', '360')"
            mode="aspectFill"
          /><!-- mode="widthFix"高度自适应 -->
        </go-detail>
      </view>
    </view>
    <!-- 列表结束 -->
  </view>
</template>

<script>
import goDetail from "@/components/goDetail";
export default {
  data() {
    return {
      // 请求参数
      param: {
        limit: 30,
        order: "new",
        skip: 0,
        first: 1, // 1表示第一次请求(返回值值中有album对象)，0表示不是第一次请求(返回值值中没有album对象)
      },
      // 请求id
      id: "",
      album: {},
      wallpaper: [],
      hasMore: true,
    };
  },
  /* 页面生命周期函数，监听页面加载 */
  onLoad(options) {
    // console.log(options);
    this.id = options.id;
    this.getList();
  },
  /* 页面生命周期函数，监听页面滚动到底部的事件(非scroll-view)，常用于下拉下一页数据 */
  onReachBottom() {
    // console.log("下拉下一页数据")
    if (this.hasMore) {
      this.album.first = 0;
      this.param.skip += this.param.limit;
      this.getList();
    } else {
      uni.showToast({
        title: "已经没有数据了哦",
        duration: 2000,
        icon: "none",
      });
    }
  },
  methods: {
    /* 获取接口的数据 */
    getList() {
      this.request({
        url: `http://157.122.54.189:9088/image/v1/wallpaper/album/${this.id}/wallpaper`,
        data: this.param,
      }).then((result) => {
        console.log(result);
        if (result.res.wallpaper.length === 0) {
          this.hasMore = false;
          return;
        }
        if (Object.keys(this.album).length === 0) {
          this.album = result.res.album;
        }
        this.wallpaper = [...this.wallpaper, ...result.res.wallpaper];
      });
    },
  },
  /* 注册组件 */
  components: {
    goDetail,
  },
};
</script>

<style lang="scss">
.album_bg {
  position: relative; // 相对
  image {
  }

  .album_info {
    position: absolute; // 绝对
    width: 100%;
    left: 0;
    bottom: 0;
    display: flex;
    justify-content: space-between; // 弹性布局，两端对齐
    height: 80rpx;
    align-items: center; // 子元素垂直居中
    color: #fff;
    padding: 0 15rpx;
    .album_name {
      font-size: 40rpx;
    }

    .album_btn {
      background-color: $color-text;
      width: 152rpx;
      height: 60rpx;
      display: flex;
      justify-content: center; // 文字水平居中
      align-items: center; // 文字垂直居中
      border-radius: 10rpx;
    }
  }
}

.album_author {
  padding: 10rpx;
  .album_author_info {
    padding: 10rpx 0;
    display: flex; // 伸缩
    image {
      width: 50rpx;
    }

    .album_author_name {
      color: #000;
      padding-top: 10rpx;
      margin-left: 15rpx; // 左外边距
    }
  }

  .album_author_desc {
  }
}

.album_list {
  display: flex;
  flex-wrap: wrap; // 换行
  .album_item {
    width: 33.33%;
    border: 3rpx solid #fff;
    image {
      height: 180rpx;
    }
  }
}
</style>